package cn.kuporo.seckill.common.constants;

/**
 * @author: kuporo
 * @since: 2025/7/17
 * @description: Redis常量
 */
public interface RedisConstants {
    // ==========================缓存相关==========================
    String SECKILL_ACTIVITY_CACHE_KEY = "seckill:activity:cache:";
    String SECKILL_ACTIVITIES_CACHE_KEY = "seckill:activities:cache:";
    String SECKILL_GOODS_CACHE_KEY = "seckill:goods:cache:";
    String SECKILL_GOODSES_CACHE_KEY = "seckill:goodses:cache:";
    String SECKILL_STOCK_CACHE_KEY = "seckill:stock:cache:";
    Long FIVE_MINUTES = 5 * 60L;


    // ==========================分布式锁相关==========================
    String SECKILL_ACTIVITES_UPDATE_CACHE_LOCK_KEY = "seckill:activities:update_cache:lock:";
    String SECKILL_ACTIVITY_UPDATE_CACHE_LOCK_KEY = "seckill:activity:update_cache:lock:";
    String SECKILL_GOODSES_UPDATE_CACHE_LOCK_KEY = "seckill:goodses:update_cache:lock:";
    String SECKILL_GOODS_UPDATE_CACHE_LOCK_KEY = "seckill:goods:update_cache:lock:";
    String SECKILL_GOODS_STOCK_UPDATE_CACHE_LOCK_KEY = "seckill:goods_stock:update_cache:lock:";

    /**
     * 订单锁
     */
    String ORDER_LOCK_KEY_PREFIX = "order:lock:";

    // ==========================下单相关==========================

    String GOODS_ITEM_KEY_PREFIX = "good:";
    
    /**
     * 商品库存key
     */
    String GOODS_ITEM_STOCK_KEY_PREFIX = "goods:stock:";

    /**
     * 商品限购数量Key
     */
    String GOODS_ITEM_LIMIT_KEY_PREFIX = "goods:limit:";

    /**
     * 订单事务日志:用来防重
     */
    String ORDER_TX_KEY = "order_tx:";

    /**
     * 商品事务日志:用来防重
     */
    String GOODS_TX_KEY = "goods_tx:";

    /**
     * 务日志7天过期
     */
    long TX_LOG_EXPIRE_DAY = 7;

    /**
     * 事务日志过期秒数
     */
    long ORDER_TX_LOG_EXPIRE_SECONDS = 7 * 24 * 3600;
    

    /**
     * Lua脚本后缀
     */
    String LUA_SUFFIX = "_lua";

    /**
     * 已经执行过恢复缓存库存的操作
     */
    Long CHECK_RECOVER_STOCK_HAS_EXECUTE = 0L;

    


    // ==========================一异步下单相关==========================
    
    /**
     * 订单任务id的key
     */
    String ORDER_TASK_ID_KEY = "order:task:";

    /**
     * 通过任务id存储的订单id的key
     */
    String ORDER_TASK_ORDER_ID_KEY = "order:task:id:";

    /**
     * 订单任务过期时间秒数
     */
    long ORDER_TASK_EXPIRE_SECONDS = 24 * 3600;

    /**
     * 订单任务的TokenKey 显示有多少个凭证可以获取
     */
    String ORDER_TASK_AVAILABLE_TOKENS_KEY = "order:token:";

    /**
     * 加锁获取最新的下单许可
     */
    String LOCK_REFRESH_LATEST_AVAILABLE_TOKENS_KEY = "order:refresh:";

    /**
     * 未执行LUA脚本具体逻辑
     */
    long LUA_RESULT_NOT_EXECUTE = -100;

    /**
     * LUA脚本执行下单许可成功
     */
    long LUA_RESULT_EXECUTE_TOKEN_SUCCESS = 1;

    /**
     * 订单
     */
    String TYPE_ORDER = "type_order";

    /**
     * 下单许可
     */
    String TYPE_TASK = "type_task";
    




    // ==========================库存编排相关==========================
    /**
     * 商品库存编排
     */
    String GOODS_STOCK_BUCKETS_SUSPEND_KEY = "goods:buckets:suspend:";

    /**
     * 商品库存分桶数量
     */
    String GOODS_BUCKETS_QUANTITY_KEY = "goods:buckets:quantity:";

    /**
     * 分桶库存
     */
    String GOODS_BUCKET_AVAILABLE_STOCKS_KEY = "goods:buckets:available:";

    /**
     * 分桶编排
     */
    String GOODS_BUCKET_ARRANGEMENT_KEY = "goods:buckets:arrangement:";

    String GOODS_STOCK_BUCKETS_ALIGN_KEY = "goods:buckets:align:";

    /**
     * 库存事务列表
     */
    String STOCK_TX_KEY = "stock_tx:";


    /**
     * 执行成功
     */
    long LUA_BUCKET_STOCK_EXECUTE_SUCCESS = 1;

    /**
     * 分桶库存不存在
     */
    long LUA_BUCKET_STOCK_NOT_EXISTS = -1;

    /**
     * 暂停服务
     */
    long LUA_BUCKET_STOCK_SUSPEND = -2;

    /**
     * 校准中
     */
    long LUA_BUCKET_STOCK_CALIBRATION = -3;

    /**
     * 库存不足
     */
    long LUA_BUCKET_STOCK_NOT_ENOUGH = -4;



    /**
     * 获取Key
     */
    static String getKey(String prefix, Object value){
        return prefix + value;
    }


}
